package me.pinion.model;


import me.pinion.model.annotation.TableBind;

@TableBind(table = "userinfo")
public class UserInfo extends XModel<UserInfo>{
    public static UserInfo dao = new UserInfo();

    public UserInfo findByUser(User user){
        UserInfo userInfo = UserInfo.dao.findFirst("SELECT * FROM userinfo WHERE user=?", user.getId());
        if (userInfo == null){
            userInfo = new UserInfo();
            userInfo.set("user", user.getId());
            userInfo.set("nickname", user.getUsername());
            userInfo.save();
        }
        return userInfo;
    }

    public String getPageCover(){ return this.getStr("page_cover") == null?"#58e": this.getStr("page_cover"); }
    public String getMotto(){ return this.getStr("motto") == null? "没有箴言" : this.getStr("motto"); }
    public String getGenderString(){ return getBoolean("gender") ? "男" : "女"; }

}
